<template>
    <div style="margin-left: 25px;margin-top: 15px;">
        <!--查询条件-->
        <el-form :inline="true" :model="search" class="demo-form-inline">
            <el-form-item label="妊检日期">
                <el-date-picker v-model="search.PregnantDate" type="datetimerange" range-separator="-"
                    start-placeholder="Start date" end-placeholder="End date" value-format="YYYY-MM-DD"
                    style="width: 310px" />
            </el-form-item>
            <el-form-item label="种母耳号">
                <el-input v-model="search.Earbugles" clearable />
            </el-form-item>
            <el-form-item label="负责人">
                <el-select v-model="search.Head" clearable style="width: 123px;">
                    <el-option :label="item.name" :value="item.name" v-for="item in HeadList" :key="item.id" />
                </el-select>
            </el-form-item>
            <el-form-item>
                <el-button type="danger" size="default" :icon="Search" @click="GetPregnantList">查询</el-button>
            </el-form-item>
            <br>
            <el-form-item label="妊检结果">
                <el-select v-model="search.PreResult" clearable style="width: 123px;">
                    <el-option label="后备空怀" value="后备空怀" />
                    <el-option label="返情空怀" value="返情空怀" />
                    <el-option label="未孕空怀" value="未孕空怀" />
                    <el-option label="流产空怀" value="流产空怀" />
                    <el-option label="空胎空怀" value="空胎空怀" />
                    <el-option label="断奶空怀" value="断奶空怀" />
                    <el-option label="妊娠" value="妊娠" />
                    <el-option label="哺乳" value="哺乳" />
                </el-select>
            </el-form-item>
            <el-form-item label="同胎数">
                <el-select v-model="search.PreNumber" clearable style="width: 123px;">
                    <el-option label="未知" value="0" />
                    <el-option label="1" value="1" />
                    <el-option label="2" value="2" />
                    <el-option label="3" value="3" />
                    <el-option label="4" value="4" />
                    <el-option label="5" value="5" />
                </el-select>
            </el-form-item>
        </el-form>

        <div style="margin-top: 9px;">
            <el-button type="danger" size="default" :icon="Plus" @click="OpenAdd">新增</el-button>
            <el-button type="danger" size="default" :icon="Delete" @click="DelAll">删除</el-button>
        </div>

        <!-- 列表 -->
        <div style="margin-top: 25px;">
            <el-table :data="PregnantList" stripe style="width: 85%" @selection-change="GetPregnantIds">
                <el-table-column type="selection" width="35" fixed align="center" />
                <el-table-column label="序号" align="center" fixed>
                    <template #default="a">
                        <span>{{ a.$index + (page.pageIndex - 1) * page.pageSize + 1 }}</span>
                    </template>
                </el-table-column>
                <el-table-column prop="preDate" label="妊检日期" align="center" width="130">
                    <template v-slot="a">
                        <span v-if="a.row.preDate"> {{ a.row.preDate.substring(0, 10) }}</span>
                    </template>
                </el-table-column>
                <el-table-column prop="earbugles" label="耳号" align="center" width="130" />
                <el-table-column prop="preResult" label="妊检结果" align="center" width="130" />
                <el-table-column prop="preWay" label="妊检方式" align="center" width="130" />
                <el-table-column prop="preNumber" label="同胎数" align="center" width="130" />
                <el-table-column prop="preDays" label="妊娠天数" align="center" width="130" />
                <el-table-column prop="currentCottage" label="当前栋舍" align="center" width="130" />
                <el-table-column prop="currentFieldName" label="当前栏位" align="center" width="130" />
                <el-table-column prop="transferCottage" label="转入栋舍" align="center" />
                <el-table-column prop="transferFieldName" label="转入栏位" align="center" width="130" />
                <el-table-column prop="personCharge" label="负责人" align="center" width="130px" />
                <el-table-column prop="createBy" label="创建人" align="center" />
                <el-table-column prop="createDate" label="创建时间" align="center" width="130px">
                    <template v-slot="a">
                        <span v-if="a.row.createDate"> {{ a.row.createDate.substring(0, 10) }}</span>
                    </template>
                </el-table-column>
                <el-table-column prop="updateBy" label="修改人" align="center" />
                <el-table-column prop="updateDate" label="修改时间" align="center" width="130px">
                    <template v-slot="a">
                        <span v-if="a.row.updateDate"> {{ a.row.updateDate.substring(0, 10) }}</span>
                    </template>
                </el-table-column>
                <el-table-column label="操作" align="center" fixed="right" width="130px">
                    <template v-slot="a">
                        <el-link type="primary" style="margin-right: 15px;" @click="OpenUpd(a.row.preId)">编辑</el-link>
                        <el-link type="primary" @click="PregnantDel(a.row.preId)">删除</el-link>
                    </template>
                </el-table-column>
            </el-table>
        </div>

        <!-- 分页 -->
        <table style="margin: auto;margin-left: 300px;margin-top: 25px;">
            <tbody>
                <tr>
                    <td>
                        <el-pagination v-model:current-page="page.pageIndex" v-model:page-size="page.pageSize"
                            :page-sizes="[15, 20, 35, 50]" :background="true" layout="total, slot,sizes"
                            :total="page.totalCount" @size-change="handleSizeChange"
                            @current-change="handleCurrentChange" prev-text="上一页" next-text="下一页">
                            <span>，共{{ page.pageCount }}页，当前第{{ page.pageIndex }}/{{
                                page.pageCount
                            }}页</span>
                        </el-pagination>
                    </td>
                    <td>
                        <el-pagination v-model:current-page="page.pageIndex" v-model:page-size="page.pageSize"
                            :page-sizes="[15, 20, 35, 50]" :background="true" layout="slot, prev, pager, next"
                            :total="page.totalCount" @size-change="handleSizeChange"
                            @current-change="handleCurrentChange" prev-text="上一页" next-text="下一页">
                            <button class="btn-prev" @click="handleCurrentChange(1)" :disabled="page.pageIndex == 1">
                                首页
                            </button>
                        </el-pagination>
                    </td>
                    <td>
                        <el-pagination v-model:current-page="page.pageIndex" v-model:page-size="page.pageSize"
                            :page-sizes="[15, 20, 35, 50]" :background="true" layout="slot, jumper"
                            :total="page.totalCount" @size-change="handleSizeChange"
                            @current-change="handleCurrentChange" prev-text="上一页" next-text="下一页">
                            <button class="btn-next" @click="handleCurrentChange(page.pageCount)"
                                :disabled="page.pageIndex == page.pageCount">
                                尾页
                            </button>
                        </el-pagination>
                    </td>
                </tr>
            </tbody>
        </table>


        <!-- 弹出层添加 -->
        <el-dialog v-model="dialogVisible" title="添加妊检信息" width="1300" style="height: 600px;">
            <span>
                <div class="dialog-footer">
                    <div style="margin-left: 25px;margin-top: 15px">
                        <div>
                            <el-button type="danger" size="default" :icon="Plus" @click="AddRow"
                                v-show="PregnantInfo.preId == 0">新增</el-button>
                            <el-button type="danger" size="default" :icon="Document" @click="PregnantCreate"
                                v-show="PregnantInfo.preId == 0">保存</el-button>
                            <el-button type="danger" size="default" :icon="Document" v-show="PregnantInfo.preId != 0"
                                @click="PregnantUpdate">修改</el-button>

                        </div>
                        <div style="margin-top: 25px;margin-left: 25px">
                            <el-form :inline="true" :model="PregnantInfo" class="demo-form-inline">
                                <el-form-item label="*负责人">
                                    <el-select v-model="PregnantInfo.personCharge" filterable placeholder="请选择"
                                        style="width: 110px" @change="GetSheepInfo">
                                        <el-option v-for="item in HeadList" :key="item.name" :label="item.name"
                                            :value="item.name" />
                                    </el-select>
                                </el-form-item>
                                <el-form-item label="*妊检日期">
                                    <el-date-picker v-model="PregnantInfo.predate" type="date" placeholder="请选择"
                                        clearable value-format="YYYY-MM-DD" style="width: 150px;" />
                                </el-form-item>
                            </el-form>
                        </div>
                        <div style="margin-top: 35px;">
                            <el-table style="width: 90%" :data="RowList">
                                <el-table-column label="序号" align="center">
                                    <template #default="a">
                                        <span>{{ a.$index + (page.pageIndex - 1) * page.pageSize + 1 }}</span>
                                    </template>
                                </el-table-column>
                                <el-table-column label="*耳号" align="center" width="130">
                                    <template v-slot="a">
                                        <span v-if="activeIndex == a.$index">
                                            <el-select v-model="PregnantInfo.earbugles" filterable placeholder="请输入"
                                                style="width: 98px" @change="GetSheepInfo">
                                                <el-option v-for="item in ZMEarList" :key="item.name" :label="item.name"
                                                    :value="item.name" />
                                            </el-select>
                                        </span>
                                    </template>
                                </el-table-column>
                                <el-table-column label="*妊检结果" align="center" width="130">
                                    <template v-slot="a">
                                        <span v-if="activeIndex == a.$index">
                                            <el-select v-model="PregnantInfo.preResult" clearable style="width: 98px;">
                                                <el-option label="后备空怀" value="后备空怀" />
                                                <el-option label="返情空怀" value="返情空怀" />
                                                <el-option label="未孕空怀" value="未孕空怀" />
                                                <el-option label="流产空怀" value="流产空怀" />
                                                <el-option label="空胎空怀" value="空胎空怀" />
                                                <el-option label="断奶空怀" value="断奶空怀" />
                                                <el-option label="妊娠" value="妊娠" />
                                                <el-option label="哺乳" value="哺乳" />
                                            </el-select>
                                        </span>
                                    </template>
                                </el-table-column>
                                <el-table-column label="*妊检方式" align="center" width="130">
                                    <template v-slot="a">
                                        <span v-if="activeIndex == a.$index">
                                            <el-select v-model="PregnantInfo.preWay" clearable style="width: 98px;">
                                                <el-option label="公羊试情" value="公羊试情" />
                                                <el-option label="人工检查" value="人工检查" />
                                                <el-option label="B超检查" value="B超检查" />
                                            </el-select>
                                        </span>
                                    </template>
                                </el-table-column>
                                <el-table-column label="同胎数" align="center" width="130">
                                    <template v-slot="a">
                                        <span v-if="activeIndex == a.$index">
                                            <el-input v-model="PregnantInfo.preNumber" style="width: 98px" />
                                        </span>
                                    </template>
                                </el-table-column>
                                <el-table-column label="妊娠天数" align="center" width="130">
                                    <template v-slot="a">
                                        <span v-if="activeIndex == a.$index">
                                            <el-input v-model="PregnantInfo.preDays" style="width: 98px" />
                                        </span>
                                    </template>
                                </el-table-column>
                                <el-table-column label="当前栋舍" align="center" width="130">
                                    <template v-slot="a">
                                        <span v-if="activeIndex == a.$index">
                                            <el-input v-model="PregnantInfo.currentCottage" style="width: 98px"
                                                readonly />
                                        </span>
                                    </template>
                                </el-table-column>
                                <el-table-column label="当前栏位" align="center" width="130">
                                    <template v-slot="a">
                                        <span v-if="activeIndex == a.$index">
                                            <el-input v-model="PregnantInfo.currentFieldName" style="width: 98px"
                                                readonly />
                                        </span>
                                    </template>
                                </el-table-column>
                                <el-table-column label="转入栋舍" align="center" width="130">
                                    <template v-slot="a">
                                        <span v-if="activeIndex == a.$index">
                                            <el-select v-model="PregnantInfo.transferCottage" clearable
                                                style="width: 98px;" @change="InGetHandleGetSheepFarm">
                                                <el-option :label="item.Name" :value="item.Name"
                                                    v-for="item in InCottagerList" />
                                            </el-select>
                                        </span>
                                    </template>
                                </el-table-column>
                                <el-table-column label="转入栏位" align="center" width="130">
                                    <template v-slot="a">
                                        <span v-if="activeIndex == a.$index">
                                            <el-select v-model="PregnantInfo.transferFieldName" clearable
                                                style="width: 110px;">
                                                <el-option :label="item.Name" :value="item.Name"
                                                    v-for="item in InColunmList" :key="item.Id" />
                                            </el-select>
                                        </span>
                                    </template>
                                </el-table-column>
                            </el-table>
                        </div>
                    </div>
                </div>
            </span>
        </el-dialog>
    </div>
</template>





<script setup lang="ts">
import { ref, reactive, inject, onMounted } from 'vue'
import { ElMessage, ElMessageBox } from 'element-plus';
import {
    Plus, Document, Delete, Back, Search
} from '@element-plus/icons-vue'
import http from '@/http'
import Enumerable from "linq";



//计算日期之间的天数
const DateDiffer = (Date_end: any) => {
    //date1结束时间
    let date1 = new Date(Date_end);
    //date2当前时间
    let date2 = new Date();
    // date1 = new Date(date1.getFullYear(), date1.getMonth(), date1.getDate());
    // date2 = new Date(date2.getFullYear(), date2.getMonth(), date2.getDate());
    const diff = date2.getTime() - date1.getTime(); //目标时间减去当前时间
    const diffDate = diff / (24 * 3600 * 1000); //计算当前时间与结束时间之间相差天数
    return Math.ceil(diffDate);
};


interface selectList {
    id: "",
    name: ""
}
//获取负责人信息
const HeadList = ref<selectList[]>([]);
const GetHeadList = () => {
    http.get("Readroute/api/StaffInfo/GetStaff").then(x => {
        HeadList.value = x.data;
    })
}


//修改种母妊检信息
const OpenUpd = (id: any) => {
    dialogVisible.value = true;
    RowList.value = [];
    AddRow();
    http.get("RouteRead/api/Pregnants/PregnantBackfill?Id=" + id).then(x => {
        PregnantInfo.preId = x.data.preId;
        PregnantInfo.earbugles = x.data.earbugles;
        PregnantInfo.predate = x.data.preDate;
        PregnantInfo.preResult = x.data.preResult;
        PregnantInfo.preWay = x.data.preWay;
        PregnantInfo.preNumber = x.data.preNumber;
        PregnantInfo.currentCottage = x.data.currentCottage;
        PregnantInfo.currentFieldName = x.data.currentFieldName;
        PregnantInfo.transferCottage = x.data.transferCottage;
        PregnantInfo.transferFieldName = x.data.transferFieldName;
        PregnantInfo.personCharge = x.data.personCharge;
        PregnantInfo.preDays = x.data.preDays;
        PregnantInfo.createBy = x.data.createBy;
        PregnantInfo.createDate = x.data.createDate;
        PregnantInfo.updateBy = x.data.updateBy;
        PregnantInfo.updateDate = x.data.updateDate;
        PregnantInfo.isDel = x.data.isDel;
    })
}
const PregnantUpdate = () => {
    //根据耳号获取种母历史记录信息
    http.get("RouteRead/api/Historys/HistoryEarsel?EarNumber=" + PregnantInfo.earbugles).then(res => {
        var info = res.data;

        //更改档案信息的栋舍信息
        SheepUpd.earNumber = PregnantInfo.earbugles;
        SheepUpd.cottage = PregnantInfo.currentCottage;
        SheepUpd.field = PregnantInfo.currentFieldName;
        http.put("Mroute/api/SheepFile/SheepFileConditionAuricleUpdate", SheepUpd)

        http.put("Kroute/api/Pregnants/PregnantUpdate", PregnantInfo).then(x => {
            if (x.data > 0) {
                ElMessage.success("修改妊检信息成功")

                //更改档案的妊检结果
                http.get("MYroute/api/SheepFile/SheepFileConditionFinds?card=" + PregnantInfo.earbugles).then(res => {
                    var form = res.data;
                    if (PregnantInfo.preResult == "后备空怀") {
                        form.reproductiveState = 1;
                        info.isEnd = true;//本次生产周期已经结束
                    } else if (PregnantInfo.preResult == "返情空怀") {
                        form.reproductiveState = 2;
                        info.isEnd = true;//本次生产周期已经结束
                    } else if (PregnantInfo.preResult == "未孕空怀") {
                        form.reproductiveState = 3;
                        info.isEnd = true;//本次生产周期已经结束
                    } else if (PregnantInfo.preResult == "流产空怀") {
                        form.reproductiveState = 4;
                        info.isEnd = true;//本次生产周期已经结束
                    } else if (PregnantInfo.preResult == "空胎空怀") {
                        form.reproductiveState = 5;
                        info.isEnd = true;//本次生产周期已经结束
                    } else if (PregnantInfo.preResult == "断奶空怀") {
                        form.reproductiveState = 6;
                        info.isEnd = true;//本次生产周期已经结束
                    } else if (PregnantInfo.preResult == "妊娠") {
                        form.reproductiveState = 7;
                    } else if (PregnantInfo.preResult == "哺乳") {
                        form.reproductiveState = 8;
                    }
                    form.pregnancyTest = true;//妊检状态改为已妊检
                    http.put("Mroute/api/SheepFile/SheepFileConditionUpdate", form)

                    info.pregnancyCheckDate = PregnantInfo.predate;//种母历史种母耳号
                    info.pregnancyCheckResult = PregnantInfo.preResult;//种母历史配种日期
                    //更改种母历史记录
                    http.post("Kroute/api/Historys/HistoryCreate", info);
                })

                dialogVisible.value = false;
                GetPregnantList();
            } else {
                ElMessage.error("修改妊检信息失败")
            }
        })
    })

}


//批量删除
var PregnantIds = ref("");
const GetPregnantIds = (ids: any) => {
    for (let index = 0; index < ids.length; index++) {
        PregnantIds.value += ids[index].preId + ",";
    }
}
const AllOronly = ref(false);
const DelAll = () => {
    AllOronly.value = true;
    PregnantDel(PregnantIds.value.substring(0, PregnantIds.value.length - 1));
}
//删除转舍信息
const PregnantDel = (id: any) => {
    ElMessageBox.confirm(
        '确定要删除吗?',
        '提示',
        {
            confirmButtonText: '确认',
            cancelButtonText: '取消',
            type: 'error',
        }
    )
        .then(() => {
            http.delete("Kroute/api/Pregnants/PregnantDelete?Ids=" + id).then(x => {
                if (x.data > 0) {
                    ElMessage.success("种母妊检记录删除成功")

                    if (AllOronly.value == true) {
                        AllOronly.value = false;
                        var ids = id.split(",");
                        ids.forEach((a: any) => {
                            //将转入的栋舍信息回退
                            http.get("RouteRead/api/Pregnants/PregnantBackfill?Id=" + a).then(x => {
                                SheepUpd.earNumber = x.data.earbugles;
                                SheepUpd.cottage = x.data.currentBuilding;
                                SheepUpd.field = x.data.currentField;
                                http.put("Mroute/api/SheepFile/SheepFileConditionAuricleUpdate", SheepUpd)
                            })
                        });
                    } else {
                        //将转入的栋舍信息回退
                        http.get("RouteRead/api/Pregnants/PregnantBackfill?Id=" + id).then(x => {
                            SheepUpd.earNumber = x.data.earbugles;
                            SheepUpd.cottage = x.data.currentBuilding;
                            SheepUpd.field = x.data.currentField;
                            http.put("Mroute/api/SheepFile/SheepFileConditionAuricleUpdate", SheepUpd)
                        })
                    }



                    GetPregnantList();
                } else {
                    ElMessage.error("种母妊检记录删除失败")
                }
            })
        })
        .catch(() => {
            ElMessage({
                type: 'info',
                message: '已取消操作',
            })
        })
}

//查询条件
const search = reactive({
    PregnantDate: [],
    Earbugles: "",
    Head: "",
    PreResult: "",
    PreNumber: "",
})
//分页数据
const page = reactive({
    pageIndex: 1,
    pageSize: 10,
    totalCount: 0,
    pageCount: 0
})
const pregnantList = ref([]);
const GetpregnantList = () => {

}
const handleSizeChange = (val: any) => {
    page.pageSize = val;
    GetpregnantList();
}
const handleCurrentChange = (val: any) => {
    page.pageIndex = val;
    GetpregnantList();
}


//控制弹出层
const dialogVisible = ref(false);
const OpenAdd = () => {
    PregnantInfo.preId = 0;
    PregnantInfo.personCharge = null;
    PregnantInfo.predate = null;
    dialogVisible.value = true;
    RowList.value = [];
}

//新增行操作
var activeIndex = ref(-1);
var RowList = ref<{}[]>([])
const AddRow = () => {
    var newRow = {
        "preResult": null,
        "preWay": null,
        "predate": null,
        "earbugles": null,
        "preNumber": null,
        "pregnancy": null,
        "currentCottage": null,
        "currentFieldName": null,
        "transferCottage": null,
        "transferFieldName": null,
        "personCharge": null
    }
    RowList.value.push(newRow);
    activeIndex.value = RowList.value.length - 1;
}


//添加妊检信息
const PregnantInfo = reactive({
    "createBy": "string",
    "createDate": "2024-05-05T09:23:58.953Z",
    "updateBy": "string",
    "updateDate": "2024-05-05T09:23:58.953Z",
    "isDel": false,
    "preId": 0,
    "preDays": null,
    "preResult": null,
    "preWay": null,
    "predate": null,
    "earbugles": null,
    "preNumber": null,
    "pregnancy": null,
    "currentCottage": null,
    "currentFieldName": null,
    "transferCottage": null,
    "transferFieldName": null,
    "personCharge": null
})
const PregnantCreate = () => {
    http.get("RouteRead/api/Historys/HistoryEarsel?EarNumber=" + PregnantInfo.earbugles).then(res => {
        var info = res.data;
        if (!PregnantInfo.personCharge) {
            ElMessage.error("请输入负责人")
            return;
        }
        if (!PregnantInfo.predate) {
            ElMessage.error("请选择妊检日期")
            return;
        }
        if (!PregnantInfo.earbugles) {
            ElMessage.error("请输入耳号")
            return;
        }
        if (!PregnantInfo.preResult) {
            ElMessage.error("请选择妊检结果")
            return;
        }
        if (!PregnantInfo.preWay) {
            ElMessage.error("请选择妊检方式")
            return;
        }


        //更改档案信息的栋舍信息
        SheepUpd.earNumber = PregnantInfo.earbugles;
        SheepUpd.cottage = PregnantInfo.transferCottage;
        SheepUpd.field = PregnantInfo.transferFieldName;
        http.put("Mroute/api/SheepFile/SheepFileConditionAuricleUpdate", SheepUpd)

        http.post("Kroute/api/Pregnants/PregnantCreate", PregnantInfo).then(x => {
            if (x.data > 0) {
                ElMessage.success("种母妊检信息保存成功")
                GetPregnantList();
                dialogVisible.value = false;


                //更改档案的妊检结果
                http.get("MYroute/api/SheepFile/SheepFileConditionFinds?card=" + PregnantInfo.earbugles).then(res => {
                    var form = res.data;
                    if (PregnantInfo.preResult == "后备空怀") {
                        form.reproductiveState = 1;
                        info.isEnd = true;//本次生产周期已经结束
                    } else if (PregnantInfo.preResult == "返情空怀") {
                        form.reproductiveState = 2;
                        info.isEnd = true;//本次生产周期已经结束
                    } else if (PregnantInfo.preResult == "未孕空怀") {
                        form.reproductiveState = 3;
                        info.isEnd = true;//本次生产周期已经结束
                    } else if (PregnantInfo.preResult == "流产空怀") {
                        form.reproductiveState = 4;
                        info.isEnd = true;//本次生产周期已经结束
                    } else if (PregnantInfo.preResult == "空胎空怀") {
                        form.reproductiveState = 5;
                        info.isEnd = true;//本次生产周期已经结束
                    } else if (PregnantInfo.preResult == "断奶空怀") {
                        form.reproductiveState = 6;
                        info.isEnd = true;//本次生产周期已经结束
                    } else if (PregnantInfo.preResult == "妊娠") {
                        form.reproductiveState = 7;
                    } else if (PregnantInfo.preResult == "哺乳") {
                        form.reproductiveState = 8;
                    }
                    form.pregnancyTest = true;//妊检状态为已妊检
                    http.put("Mroute/api/SheepFile/SheepFileConditionUpdate", form)


                    info.pregnancyCheckDate = PregnantInfo.predate;//种母历史种母耳号
                    info.pregnancyCheckResult = PregnantInfo.preResult;//种母历史配种日期
                    //添加种母历史记录
                    http.post("Kroute/api/Historys/HistoryCreate", info);
                })

            } else {
                ElMessage.error("种母妊检信息保存失败")
            }
        })

    })
}

//羊只档案
//羊只档案表单
const form1 = reactive({
    "id": 0,
    "visualEarSignal": "",
    "electronicEarNumber": "",
    "breed": "",
    "sex": "",
    "birthday": "",
    "ageDays": "",
    "ageMoon": "",
    "presence": "",
    "growthStage": "",
    "sheepType": "",
    "cottage": "",
    "field": "",
    "reproductiveState": 0,
    "pregnancyTest": true,
    "statusDays": "",
    "productionGrade": "",
    "salesGrade": "",
    "geneClass": "",
    "birthWeight": "",
    "weaningWeight": "",
    "weaningDate": "",
    "weaningAge": "",
    "fatherHorn": "",
    "femaleHorn": "",
    "earNumber": "",
    "placeBirth": "",
    "remark": "",
    "createBy": "",
    "createDate": "",
    "updateBy": "",
    "updateDate": "",
})


//栋舍
const CottagerList = ref<{
    Id: "",
    Name: ""
}[]>([]);
const GetHandleGetCot = () => {
    http.get("OrganizationRead/api/Cottage/HandleGetCot").then(x => {
        CottagerList.value = x.data;
    })
}
const ColunmList = ref<{
    CottageId: "",
    Id: "",
    Name: ""
}[]>([]);
const GetHandleGetSheepFarm = () => {
    if (PregnantInfo.currentCottage) {
        http.get("OrganizationRead/api/Field/HandleGetSheepFarm?Id=" + PregnantInfo.currentCottage).then(x => {
            ColunmList.value = x.data;
        })
    }
}


//转入栋舍和栏位
const InCottagerList = ref<{
    Id: "",
    Name: ""
}[]>([]);
const InGetHandleGetCot = () => {
    http.get("OrganizationRead/api/Cottage/HandleGetCot").then(x => {
        InCottagerList.value = x.data;
    })
}
const InColunmList = ref<{
    CottageId: "",
    Id: "",
    Name: ""
}[]>([]);
const InGetHandleGetSheepFarm = () => {
    if (PregnantInfo.transferCottage) {
        http.get("OrganizationRead/api/Field/HandleGetSheepFarm?Id=" + PregnantInfo.transferCottage).then(x => {
            InColunmList.value = x.data;
        })
    }
}

//获取妊检信息
const PregnantList = ref([]);
const GetPregnantList = () => {
    var dates = "";
    if (search.PregnantDate) {
        dates = search.PregnantDate.join(",");
    }
    http.get("RouteRead/api/Pregnants/PregnantSelect", {
        params: {
            pageIndex: page.pageIndex,
            pageSize: page.pageSize,
            PregnantDate: dates,
            Earbugles: search.Earbugles,
            Head: search.Head,
            PreResult: search.PreResult,
            PreNumber: search.PreNumber || 0,
        }
    }).then(x => {
        PregnantList.value = x.data.datas;
        page.totalCount = x.data.totalCount;
        page.pageCount = x.data.pageCount;
    })
}



//获取种公种母后裔耳标（分类后）
const ZMEarList = ref<{
    name: ""
}[]>([]);
const ZGEarList = ref<{
    name: ""
}[]>([]);
const HYEarList = ref<{
    name: ""
}[]>([]);
const GetEarList = () => {
    http.get("MYroute/api/SheepFile/SheepFileConditionarchives").then(x => {
        x.data.forEach((a: any) => {
            if (a.sheepType == "种母" && a.reproductiveState == "妊娠") {
                ZMEarList.value.push({
                    name: a.card
                })
            } else if (a.sheepType == "种公") {
                ZGEarList.value.push({
                    name: a.card
                })
            } else {
                HYEarList.value.push({
                    name: a.card
                })
            }
        });
    })
}
//根据耳号获取羊只档案信息
const GetSheepInfo = () => {
    http.get("MYroute/api/SheepFile/SheepFileConditionFinds?card=" + PregnantInfo.earbugles).then(x => {
        PregnantInfo.currentCottage = x.data.cottage;
        PregnantInfo.currentFieldName = x.data.field;
        http
            .get(
                "RouteRead/api/Breedings/GetBreedingForEar?EarNumber=" + PregnantInfo.earbugles
            )
            .then((res) => {
                var maxDate = Enumerable.from(res.data).max((a: any) => a.breedingDate);
                PregnantInfo.preDays = DateDiffer(maxDate);
            });
    })
}



//修改羊只档案信息
var SheepUpd = reactive({
    earNumber: null,
    cottage: null,
    field: null,
})

onMounted(() => {
    GetHandleGetCot();
    InGetHandleGetCot();
    GetPregnantList();
    GetHeadList();
    GetEarList();
})

</script>


<style></style>